package org.example.doctorapi.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.validation.constraints.NotNull;
import org.example.doctorapi.aspectMethods.LogAnnotation;
import org.example.doctorapi.data.SysDictData;
import org.example.doctorapi.server.SysDictDataServer;
import org.example.doctorcommon.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/dict")
public class DictDataController {
    @Autowired
    private SysDictDataServer sysDictDataServer;
    @GetMapping("/listDorPage")
    @LogAnnotation
    public BaseResult findAll(@NotNull(message = "页数不能空") int page
            , @NotNull(message = "页面条数不能空") int size){
        SysDictData sysDictData = new SysDictData();
        sysDictData.setPageSize(page);
        sysDictData.setPageSize(size);
        return BaseResult.ok(sysDictDataServer.checkDictDataAll(sysDictData));
    }
    @GetMapping("/type/listForPage")
    public BaseResult gateDictData(@RequestBody @Validated SysDictData sysDictData){
        return BaseResult.ok(sysDictDataServer.checkDictDataSome(sysDictData));
    }
    @GetMapping("/getOne/{dictId}")
    public BaseResult getOneDict(@PathVariable @Validated @NotNull(message = "字典ID不能为空") Integer dictId){
        return BaseResult.ok(sysDictDataServer.getOneByDictId(dictId));
    }
    @PostMapping("/addDictData")
    public BaseResult addDictData(@RequestBody @Validated SysDictData sysDictData){
        sysDictDataServer.insertOne(sysDictData);
        return BaseResult.ok("修改成功");
    }

    @PostMapping("/update")
    public BaseResult updateDictData(@RequestBody @Validated SysDictData sysDictData){
        sysDictDataServer.updateOne(sysDictData);
        return BaseResult.ok("修改成功");
    }


    @DeleteMapping("/deleteAll")
    public BaseResult DeleteDictAll(List<Integer> ids){
        sysDictDataServer.deleteAll(ids);
        return BaseResult.ok("删除成功");
    }

    @DeleteMapping("/deleteDictDataByIds/{dictIds}")
    public BaseResult DeleteDictAll(@PathVariable int dictIds){
        sysDictDataServer.deleteById(dictIds);
        return BaseResult.ok("删除成功");
    }
}
